/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package marcin.belzowski.geoMap;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 *
 * @author marcin
 */
@Entity
@Table(name = "car")
@NamedQueries({@NamedQuery(name = "Car.findAll", query = "SELECT c FROM Car c"), @NamedQuery(name = "Car.findById", query = "SELECT c FROM Car c WHERE c.id = :id"), @NamedQuery(name = "Car.findByIdgps", query = "SELECT c FROM Car c WHERE c.idgps = :idgps")})
public class Car implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "idgps")
    private BigInteger idgps;
    @OneToMany(cascade = {CascadeType.ALL})
    @PrimaryKeyJoinColumn()
    private Collection<Position> positions;

    public Car() {
    }

    public Car(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public BigInteger getIdgps() {
        return idgps;
    }

    public void setIdgps(BigInteger idgps) {
        this.idgps = idgps;
    }

    public Collection<Position> getPositions() {
        return positions;
    }

    public void setPositions(Position p) {

        if (null == positions) {
            positions = new ArrayList<Position>();

        }
        positions.add(p);

    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Car)) {
            return false;
        }
        Car other = (Car) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "marcin.belzowski.geoMap.Car[id=" + id + "]";
    }

    public static void main(String[] args){

    }
}
